//P1706全排列

#include <bits/stdc++.h>

using namespace std;

int number[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9};

int vis[100] = {0};

int ans[100] = {0};

void dfs(int s, int e)
{
    if(s == e){
        for(int i = 0; i < e; i++){
            std::cout << "    "<< ans[i] ;
        }
        std::cout << std::endl;
    }else{
        for(int i = 0; i < e; i++){
            if(vis[i])  continue;
            vis[i] = 1;
            ans[s] = number[i];
            dfs(s + 1, e);
            vis[i] = 0;
        }
    }
}

int main(){
    int n = 0;
    cin >> n;
    dfs(0, n);
}